class JobsController < ApplicationController

  before_filter :login_required

  def index
    @jobs = current_user.jobs
  end

  def new
    @job = Job.new
  end

  def edit
    @job = current_user.jobs.find(params[:id])
  end

  def create
    @job = Job.new(params[:job])
    @job.user = current_user

    respond_to do |format|
      if @job.save
        flash[:notice] = 'Job was successfully created.'
        format.html { redirect_to jobs_url }
      else
        format.html { render :action => "new" }
      end
    end
  end

  def update
    @job = current_user.jobs.find(params[:id])

    respond_to do |format|
      if @job.update_attributes(params[:job])
        flash[:notice] = 'Job was successfully updated.'
        format.html { redirect_to jobs_url }
      else
        format.html { render :action => "edit" }
      end
    end
  end

  def destroy
    @job = current_user.jobs.find(params[:id])
    @job.destroy

    respond_to do |format|
      format.html { redirect_to jobs_url }
    end
  end
end
